package com.hz.qs.controller;


import com.hz.qs.service.LoginService;
import com.hz.qs.utils.RestResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 登录controller
 *
 * @author yejy
 * @date 2020/10/29 15:59
 */
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     *
     * 登录
     * @author yejy
     * @date 2020/11/2 09:43
     * @param httpSession
     * @param userName
     * @param password
     * @return com.hz.qs.utils.RestResult
     */
    @ApiOperation("login")
    @PostMapping("/login")
    public RestResult login(HttpSession httpSession, @RequestParam("userName") String userName, @RequestParam("password") String password) {
        return loginService.loginOpt(httpSession, userName, password);
    }


    @ApiOperation("退出登录")
    @GetMapping("/logout")
    public RestResult logout(HttpSession httpSession){
        loginService.logout(httpSession);
        return RestResult.successResult(null);
    }


    @GetMapping("hello")
    public RestResult hello() {
        return RestResult.successResult("hhhhhh");
    }
}